package cn.hist.hfp.converter;

import cn.hist.hfp.entity.Comment;
import cn.hist.hfp.vo.CommentVO;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Component
public class CommentConverter {

    public CommentVO covert(Comment comment) {
        return CommentVO.builder()
                .id(comment.getId())
                .content(comment.getContent())
                .userId(comment.getUser().getId())
                .userName(comment.getUser().getName())
                .strayId(comment.getStray().getId()).build();
    }

    public Set<CommentVO> covert(Set<Comment> comments) {
        Set<CommentVO> commentVOS = new HashSet<>();
        for (Comment comment: comments) {
            commentVOS.add(covert(comment));
        }
        return commentVOS;
    }

    public List<CommentVO> covert(List<Comment> comments) {
        List<CommentVO> commentVOS = new ArrayList<>();
        for (Comment comment: comments) {
            commentVOS.add(covert(comment));
        }
        return commentVOS;
    }
}
